package com.hexacta.hrs.web.struts.actions;

import com.hexacta.hrs.services.crud.CrudService;
import com.hexacta.hrs.services.timeoff.AvailableLicenseDaysService;
import com.hexacta.hrs.services.timeoff.CompensationDaysService;
import com.hexacta.hrs.timeoff.AvailableLicenseDays;
import com.hexacta.hrs.timeoff.CompensationDaysAssignation;

/**
 * 
 * Action de Struts para eliminar {@link CompensationDaysAssignation}.
 * 
 * @author vschimpf
 * 
 */
public final class DeleteCompensationDaysAction extends CrudAbstractAction<CompensationDaysAssignation> {

    private static final long serialVersionUID = 2458931116623003779L;

    private CompensationDaysService compensationDaysService;
    private AvailableLicenseDaysService availableLicenseDaysService;

    public void setAvailableLicenseDaysService(AvailableLicenseDaysService availableLicenseDaysService) {
		this.availableLicenseDaysService = availableLicenseDaysService;
	}

	@Override
    protected CrudService<CompensationDaysAssignation> getCrudService() {
        return compensationDaysService;
    }
    
    public void setCompensationDaysService(final CompensationDaysService compensationDaysService) {
        this.compensationDaysService = compensationDaysService;
    }
    
    public String validateDelete() {
    	AvailableLicenseDays availableLicenseDays = this.availableLicenseDaysService.getAvailableLicenseDays(getModel().getAssignedTo());
    	availableLicenseDays.setCompensationDays(availableLicenseDays.getCompensationDays() - getModel().getQuantity());
    	this.availableLicenseDaysService.save(availableLicenseDays);
    	
    	getCrudService().delete(getModel());
    	    	
		return list();
	}

}
